package com.lsh.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;

import javax.servlet.ServletException;

import com.lsh.common.util.SysUtil;

public abstract class AbstractManagerAction extends BasicAction {

	private static final long serialVersionUID = 1L;

	public void checkRights(String rightCode) throws ServletException,
			IOException {
		HashSet rights = (HashSet) get("rights");
		if (!rights.contains(rightCode.toUpperCase())) {// 没有权限
			System.out.println("没有权限");
			message = "对不起，您没有该操作权限";
			request.getRequestDispatcher("/system/message.jsp").forward(
					request, response);// 跳转
		} else {
			System.out.println("有权限，继续");
		}
	}

	/**
	 * @param statusCode 200-操作成功，300-操作失败
	 * @param message
	 * @throws IOException
	 */
	public void returnAjaxMessage(int statusCode,String message) throws IOException {
		response.setHeader("content-type", "text/html;charset=UTF-8");
		String jsonStr = SysUtil.getJsonStr(statusCode, message);
		PrintWriter writer = response.getWriter();
		writer.print(jsonStr);
		writer.flush();
		writer.close();

	}
}
